/**
 * Quadracopter Project
 * 
 * by: AR,OK,CM,MSS
 * 
 */
 
#include "system_q.h"

void main(void) {
	
	System_Init();
	
	while(1){
		System_Routine();
	}		
}

/*------------------------------------------------------------------------------
* Timer A ISR
------------------------------------------------------------------------------*/
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A (void)
{
  gsSystem.InterruptReg |= TIMER;
}

/*------------------------------------------------------------------------------
// PORT 2 ISR 
------------------------------------------------------------------------------*/
#pragma vector=PORT2_VECTOR
__interrupt void port2_ISR (void)
{ 	
	if (RF_GDO0_PxIFG & RF_GDO0_PIN)
	{
		gsSystem.InterruptReg |= SPI;
		TXString("Incomming Command!\r\n",20);
		  // Fetch packet from CCxxxx & check the CRC==0x80 (OK)
		  if (0x80 == RFReceivePacket(gsSystem.RX_Buffer, &gsSystem.RX_Buffer_length) &&
		      (gsSystem.RX_Buffer_length == 11))
		  {
		  		if(gsSystem.RX_Buffer[1]=='R') RED_LED_TOGGLE;
		  		if(gsSystem.RX_Buffer[1]=='G') GREEN_LED_TOGGLE;
		  		if(gsSystem.RX_Buffer[2]==0xA1) {
		  			GREEN_LED_TOGGLE;
		  			RED_LED_TOGGLE;
		  			TXString("Cool Yo!\r\n",10);
		  		}
		  }
		gsSystem.RX_Buffer_length = PKTLEN;
		RF_GDO0_PxIFG &= ~RF_GDO0_PIN;
	}
}

/*------------------------------------------------------------------------------
* USCIA interrupt service routine
* UART receiving a character.
------------------------------------------------------------------------------*/
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{
	gsSystem.InterruptReg |= UART;	
}
